#!/bin/bash

echo "停止喵趣AI项目服务..."

# 停止前端服务
if [ -f "logs/frontend.pid" ]; then
    FRONTEND_PID=$(cat logs/frontend.pid)
    if kill -0 $FRONTEND_PID 2>/dev/null; then
        kill $FRONTEND_PID
        echo "✅ 前端服务已停止"
    fi
    rm -f logs/frontend.pid
fi

# 停止Celery worker
if [ -f "logs/celery.pid" ]; then
    CELERY_PID=$(cat logs/celery.pid)
    if kill -0 $CELERY_PID 2>/dev/null; then
        kill $CELERY_PID
        echo "✅ Celery worker已停止"
    fi
    rm -f logs/celery.pid
fi

# 停止Flask服务
if [ -f "logs/flask.pid" ]; then
    FLASK_PID=$(cat logs/flask.pid)
    if kill -0 $FLASK_PID 2>/dev/null; then
        kill $FLASK_PID
        echo "✅ 后端服务已停止"
    fi
    rm -f logs/flask.pid
fi

# 停止可能的其他相关进程
pkill -f "python run.py"
pkill -f "celery.*worker"
pkill -f "npm run dev"

echo "======================================"
echo "🛑 所有服务已停止"
echo "======================================"